package trace.config;

import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.io.Serializable;

public class SparkConfig implements Serializable {
    //	<localdir>/usr2/fingerTemp/data/hourfinger</localdir>
//	<hdfsinput>/data/5gmr/filegroup</hdfsinput>
//	<hdfsoutput>/data/5gmr/output</hdfsoutput>
//	<hdfsHost>hdfs://172.17.1.81:8020</hdfsHost>
//	<hdfsUser>hdfs</hdfsUser>	
    public String name, localdir, hdfsHost, hdfsUser, hdfsXdr, hdfsOut, hdfsTrace, hdfsTrace_dat, hdfsTrace_last, hdfsRootDir, hbaseRoot, hbaseZK, hbaseZKPort, hbaseNameSpace;
    public String cellKpiPath, userCellKpiPath;
    public String impala_database, impala_driver, impala_url, impala_cache;
    public int version;

    public SparkConfig(String cfgname) throws DocumentException {
        SAXReader reader = new SAXReader();
        Element root = reader.read(SparkConfig.class.getResourceAsStream(cfgname)).getRootElement();
        name = root.attributeValue("name");

        localdir = root.elementText("localdir");
        hdfsHost = root.elementText("hdfsHost");
        hdfsUser = root.elementText("hdfsUser");
        hdfsRootDir = root.elementText("hdfsRootDir");

        hdfsXdr = hdfsRootDir + root.elementText("hdfsXdr");
        hdfsTrace = hdfsRootDir + root.elementText("hdfsTrace");
        hdfsTrace_dat = hdfsRootDir + root.elementText("hdfsTrace_dat");
        hdfsTrace_last = hdfsRootDir + root.elementText("hdfsTrace_last");

        hdfsOut = hdfsRootDir + root.elementText("hdfsOut");

        cellKpiPath = hdfsRootDir + root.elementText("cellKpiPath");
        userCellKpiPath = hdfsRootDir + root.elementText("userCellKpiPath");

        hbaseRoot = root.elementText("hbaseRoot");
        hbaseZK = root.elementText("hbaseZK");
        hbaseZKPort = root.elementText("hbaseZKPort");
        hbaseNameSpace = root.elementText("hbaseNameSpace");

        impala_database = root.elementText("impala_database");
        impala_driver = root.elementText("impala_driver");
        impala_url = root.elementText("impala_url");
        impala_cache = hdfsRootDir + root.elementText("impala_cache");

        version = Integer.parseInt(root.elementText("version"));
    }

}

